package com.example.exception;

/**
 * 认证异常类
 * 用于处理用户认证相关的异常
 */
public class AuthenticationException extends BaseException {
    
    public AuthenticationException(String errorCode, String errorMessage) {
        super(errorCode, errorMessage, ErrorCategory.AUTHENTICATION);
    }
    
    public AuthenticationException(String errorCode, String errorMessage, Object errorDetails) {
        super(errorCode, errorMessage, errorDetails);
        setErrorCategory(ErrorCategory.AUTHENTICATION);
    }
    
    public AuthenticationException(String errorCode, String errorMessage, Throwable cause) {
        super(errorCode, errorMessage, cause);
        setErrorCategory(ErrorCategory.AUTHENTICATION);
    }
    
    // ========== Token相关认证异常 ==========
    
    public static AuthenticationException tokenInvalid() {
        return new AuthenticationException(ErrorCode.AUTH_TOKEN_INVALID, "Token无效");
    }
    
    public static AuthenticationException tokenExpired() {
        return new AuthenticationException(ErrorCode.AUTH_TOKEN_EXPIRED, "Token已过期");
    }
    
    public static AuthenticationException tokenMissing() {
        return new AuthenticationException(ErrorCode.AUTH_TOKEN_MISSING, "Token缺失");
    }
    
    public static AuthenticationException refreshTokenInvalid() {
        return new AuthenticationException(ErrorCode.AUTH_REFRESH_TOKEN_INVALID, "刷新Token无效");
    }
    
    // ========== 登录相关认证异常 ==========
    
    public static AuthenticationException loginFailed() {
        return new AuthenticationException(ErrorCode.AUTH_LOGIN_FAILED, "登录失败");
    }
    
    public static AuthenticationException loginFailed(String reason) {
        return new AuthenticationException(ErrorCode.AUTH_LOGIN_FAILED, "登录失败: " + reason);
    }
    
    public static AuthenticationException logoutFailed() {
        return new AuthenticationException(ErrorCode.AUTH_LOGOUT_FAILED, "登出失败");
    }
    
    // ========== 验证码相关认证异常 ==========
    
    public static AuthenticationException captchaError() {
        return new AuthenticationException(ErrorCode.AUTH_CAPTCHA_ERROR, "验证码错误");
    }
    
    public static AuthenticationException captchaExpired() {
        return new AuthenticationException(ErrorCode.AUTH_CAPTCHA_ERROR, "验证码已过期");
    }
    
    public static AuthenticationException verificationCodeError() {
        return new AuthenticationException(ErrorCode.AUTH_VERIFICATION_CODE_ERROR, "验证码错误");
    }
    
    public static AuthenticationException verificationCodeExpired() {
        return new AuthenticationException(ErrorCode.AUTH_VERIFICATION_CODE_ERROR, "验证码已过期");
    }
    
    // ========== 账户状态相关认证异常 ==========
    
    public static AuthenticationException accountLocked() {
        return new AuthenticationException(ErrorCode.AUTH_ACCOUNT_LOCKED, "账户已被锁定");
    }
    
    public static AuthenticationException accountLocked(String reason) {
        return new AuthenticationException(ErrorCode.AUTH_ACCOUNT_LOCKED, "账户已被锁定: " + reason);
    }
    
    public static AuthenticationException accountDisabled() {
        return new AuthenticationException(ErrorCode.USER_DISABLED, "账户已被禁用");
    }
    
    public static AuthenticationException accountNotActivated() {
        return new AuthenticationException(ErrorCode.USER_NOT_ACTIVATED, "账户未激活");
    }
}


